﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord;
using Mang24k99.Model.COMM;
using Castle.ActiveRecord.Queries;

namespace Mang24k99.Model.GOLD
{
    [ActiveRecord(Table = "KT_GOLD_GOLDBREED")]
    public partial class MKtGoldGoldbreed : ActiveRecordBase
    {
        public static IList<MKtGoldGoldbreed> SelectAll()
        {
            return (IList<MKtGoldGoldbreed>)FindAll(typeof(MKtGoldGoldbreed));
        }
        public static MKtGoldGoldbreed SelectByPrimaryKey(object ID)
        {
            return (MKtGoldGoldbreed)FindByPrimaryKey(typeof(MKtGoldGoldbreed), ID);
        }
        public static IList<MKtGoldGoldbreed> SelectALLByProperty(string property, object value)
        {
            return (IList<MKtGoldGoldbreed>)FindAllByProperty(typeof(MKtGoldGoldbreed), property, value);
        }
        public static IList<MKtGoldGoldbreed> SelectALLSliced(int firstResult, int maxResult, NHibernate.Expression.DetachedCriteria criteria)
        {

            return (IList<MKtGoldGoldbreed>)SlicedFindAll(typeof(MKtGoldGoldbreed), firstResult, maxResult, criteria);
        }
        protected override void OnDelete()
        {
            MKtGoldGoldbreedHistory mHistory = new MKtGoldGoldbreedHistory();
            Common.ModelCommon.CopyObjectValues(this, mHistory);
            mHistory.BreedType = MKtCommCodelist.CODE_NO;
            mHistory.DeleteTime = DateTime.Now;
            mHistory.Create();
            base.OnDelete();
        }
        /// <summary>
        /// 选择最大的品种编号
        /// </summary>
        /// <returns></returns>
        public static int GetMaxNO()
        {
            string Hql = @"select max(goldbreed.BreedNO) from MKtGoldGoldbreed goldbreed  ";
            string count = @"select count(goldbreed.BreedNO) from MKtGoldGoldbreed goldbreed ";
            ScalarQuery querycount = new ScalarQuery(typeof(MKtGoldGoldbreed), count);
            if (Convert.ToInt32(ExecuteQuery(querycount)) == 0)
            {
                return 0;
            }
            ScalarQuery query = new ScalarQuery(typeof(MKtGoldGoldbreed), Hql);
            return (int)ExecuteQuery(query);
        }
        /// <summary>
        /// 通过where条件返回记录
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static IList<MKtGoldGoldbreed> SelectByWhere(string where)
        {
            string Hql = @"from  MKtGoldGoldbreed goldbreed "+where;
            SimpleQuery query = new SimpleQuery(typeof(MKtGoldGoldbreed),Hql);
            return (IList<MKtGoldGoldbreed>)ExecuteQuery(query);
        }
        /// <summary>
        /// 创建一条记录
        /// </summary>
        /// <param name="goldbreed"></param>
        public static void Create(MKtGoldGoldbreed goldbreed)
        {
            goldbreed.Create();
        }
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="goldbreed"></param>
        public static void Delete(MKtGoldGoldbreed goldbreed)
        {
            goldbreed.Delete();
        }
        /// <summary>
        /// 修改一条记录
        /// </summary>
        /// <param name="goldbreed"></param>
        public static void Update(MKtGoldGoldbreed goldbreed)
        {
            goldbreed.Update();
        }

        [BelongsTo("BREED_TYPE", Cascade = CascadeEnum.None)]
        public MKtCommCodeList MKtCommCodelist 
        {
            get
            {
                return _MKtCommCodelist;
            }
            set
            {
                _MKtCommCodelist = value;
            }
        }

        [HasMany(typeof(MKtGoldProduct), ColumnKey = "BREED_NO", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, Inverse = true, Lazy = true)]
        public IList<MKtGoldProduct> MKtGoldProduct
        {
            get
            {
                return _MKtGoldProduct;
            }
            set
            {
                _MKtGoldProduct = value;
            }
        }

        /// <summary>
        /// Gets or sets the BreedNO.()
        /// </summary>
        /// <value>The BreedNO.</value>
        [PrimaryKey(PrimaryKeyType.Assigned, "BREED_NO")]
        public int BreedNO
        {
            get
            {
                return _BreedNO;
            }
            set
            {
                _BreedNO = value;
            }
        }


        /// <summary>
        /// Gets or sets the ID.()
        /// </summary>
        /// <value>The ID.</value>
        [Property("ID", Insert = false, Update = false)]
        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }


        /// <summary>
        /// Gets or sets the BreedName.()
        /// </summary>
        /// <value>The BreedName.</value>
        [Property("BREED_NAME")]
        public string BreedName
        {
            get
            {
                return _BreedName;
            }
            set
            {
                _BreedName = value;
            }
        }


        /// <summary>
        /// 1-关闭，0-显示
        /// </summary>
        /// <value>The CloseShow.</value>
        [Property("CLOSE_SHOW")]
        public int? CloseShow
        {
            get
            {
                return _CloseShow;
            }
            set
            {
                _CloseShow = value;
            }
        }


        /// <summary>
        /// Gets or sets the ProductBelong.()
        /// </summary>
        /// <value>The ProductBelong.</value>
        [Property("PRODUCT_BELONG")]
        public int? ProductBelong
        {
            get
            {
                return _ProductBelong;
            }
            set
            {
                _ProductBelong = value;
            }
        }


        /// <summary>
        /// 1-有效2-无效
        /// </summary>
        /// <value>The IsValidate.</value>
        [Property("IS_VALIDATE")]
        public int? IsValidate
        {
            get
            {
                return _IsValidate;
            }
            set
            {
                _IsValidate = value;
            }
        }


        /// <summary>
        /// Gets or sets the InputTime.()
        /// </summary>
        /// <value>The InputTime.</value>
        [Property("INPUT_TIME")]
        public DateTime? InputTime
        {
            get
            {
                return _InputTime;
            }
            set
            {
                _InputTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the ModifyTime.()
        /// </summary>
        /// <value>The ModifyTime.</value>
        [Property("MODIFY_TIME")]
        public DateTime? ModifyTime
        {
            get
            {
                return _ModifyTime;
            }
            set
            {
                _ModifyTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the DeleteTime.()
        /// </summary>
        /// <value>The DeleteTime.</value>
        [Property("DELETE_TIME")]
        public DateTime? DeleteTime
        {
            get
            {
                return _DeleteTime;
            }
            set
            {
                _DeleteTime = value;
            }
        }



        private int _BreedNO;

        private IList<MKtGoldProduct> _MKtGoldProduct;
        private int _ID;

        private string _BreedName;

        private MKtCommCodeList _MKtCommCodelist;
        private int? _CloseShow;

        private int? _ProductBelong;

        private int? _IsValidate;

        private DateTime? _InputTime;

        private DateTime? _ModifyTime;

        private DateTime? _DeleteTime;


    }
}
